package atri.mapper;

import atri.model.Book;
import atri.model.Booklist;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface BooklistMapper extends BaseMapper<Booklist> {
    @Select("SELECT * FROM booklist WHERE re_id = #{id}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "re_id", property = "re_id"),
            @Result(column = "book_id", property = "book_id"),
    })
    List<Booklist> find_re_id (int id);

    @Delete("DELETE FROM booklist WHERE re_id = #{id}")
    Boolean del_re_id (int id);

    @Insert({
            "<script>",
            "INSERT INTO booklist (re_id, book_id) VALUES ",
            "<foreach collection='booklists' item='booklist' separator=','>",
            "(#{booklist.re_id}, #{booklist.book_id})",
            "</foreach>",
            "</script>"
    })
    int insert_many(@Param("booklists") List<Booklist> booklists);

}
